package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     *
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /*分页查询套餐*/
    List<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    /*新增套餐*/
    @AutoFill(OperationType.INSERT)
    void save(Setmeal setmeal);

    /*套餐起售、停售*/
    @Update("update setmeal set status = #{status} where id = #{id}")
    void startOrStop(Integer status, Long id);

    /*根据id查询*/
    @Select("select s.*,c.`name` AS categoryName from setmeal s LEFT JOIN category c on s.category_id = c.id where s.id = #{id}")
    Setmeal getById(Long id);

    /*批量删除套餐 */
    void deleteBatch(List<Long> ids);

    /*修改套餐*/
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    /*根据分类id查询多个套餐*/
    @Select("select * from setmeal where category_id = #{categoryId}")
    List<Setmeal> getListCategoryId(Setmeal setmeal);

    /*根据id查询套餐和对应的菜品*/
    @Select("SELECT d.*,sd.copies AS copies FROM setmeal_dish sd LEFT JOIN dish d ON sd.dish_id = d.id WHERE sd.setmeal_id = #{id}")
    List<DishItemVO> getDishItemById(Long id);

    /**
     * 根据条件统计套餐数量
     *
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
